﻿;############################### SET ITEM PROPERTIES
QC_ItemSet( item, params )
{
	static params_list := {	name:0,issep:0,icon:0,bold:0
												,bgcolor:0,tcolor:0,mbgcolor:0,mtcolor:0,hotkey:0}	;list of possible parameters for menu item
	if !isObject( params )
		throw Exception( "Wrong parameter: " params "`n" CallStack() )
	item := qcconf.ItemResolve( item )
	for key, value in params
		if params_list.HasKey( key )
			qcconf.ItemSetAttr( item, key, value, 1 )
	if params.HasKey( "cmd" )
		qcconf.ItemSetCmd( item, params.cmd )
}
;############################### ADD XML ITEM
QC_AddXMLItem( params )
{
	Gui, 1:Default
	if !IsObject( params )
		throw Exception( "Not an object passed`n" CallStack() )
	menuNode := params.menuNode ? params.menuNode
								: params.menuID ? qcconf.GetNodeByID( params.menuID )	;any menu
								: qcconf.GetNodeByID( 0 )	;top menu
	beforeItemNode := params.afterNode ? params.afterNode.nextSibling
										: params.afterID ?  qcconf.GetNodeByID( params.afterID ).nextSibling
										: 0							; will add to the end of menu
										;~ : menuNode.firstChild		;item will be added to the top of the list
	newItemNode := qcconf.CreateItemNode( menuNode, beforeItemNode )
	QC_ItemSet( newItemNode, params )
	return newItemNode
}
;############################### MOVE ITEM
GUI_Main_TV_Move( id, tid, pid = "" )	;tid can be target id, after which moved item will be placed (0 for top), or U or D letter for move
{
	if !id
		return
	Gui,1:Default
	GuiControl,Focus,% qcGUI[ "main_tv" ]
	GuiControl, -Redraw,% qcGui[ "main_tv" ]
	if ( pid = "" )
		pid := TV_GetParent( id )
	if tid in U,D	;in case we move item with arrows
	{
		dir := tid
		tid :=  dir = "U" ? TV_GetPrev( id )
				: dir = "D" ? TV_GetNext( id ) : ""
		if !tid		;means item at the beginning or at the end of menu
			return
		if ( dir = "D" )								;getting item before which moved one should be
			tid := TV_GetNext( tid )
	}
	else if !IsInteger( tid )	;can be integer if passed from DragnDrop
		throw Exception( "invalid tid: " tid "`n" CallStack() )
	; XML CHANGES
	itemNode := qcconf.GetNodeByID( qcTVItems[ id ] )
	itemNode := itemNode.parentNode.removeChild( itemNode )
	parentNode := qcconf.GetNodeByID( qcTVItems[ pid ] )
	if ( tid && ( beforeNode := qcconf.GetNodeByID( qcTVItems[ tid ] ) ) )
		parentNode.insertBefore( itemNode, beforeNode )
	else
		parentNode.appendChild( itemNode )
	; TV CHANGES
	props := QC_TVDelProps( id )
	tid_prev := TV_GetPrev( tid )
	prevID := tid ? ( tid_prev ? tid_prev : "First" ) : 0	;determining item after which moved one will be inserted
	newTVID := QC_TVAdd( props.name, PID, prevID " " props.options, itemNode.getAttribute( "ID" ) )
	if props.hasChilds
		QC_BuildTV( newTVID, itemNode, False )
	sleep 1							; for some reason next line require small sleep to be successful :/
	TV_Modify( newTVID, "Select Vis" )
	if ( TV_GetParent( newTVID ) = PID )
		QC_ArrangeTVColors( PID )
	GuiControl, +Redraw,% qcGui[ "main_tv" ]

	return newTVID
}